package com.edu.boot.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edu.boot.entity.SResume;
import com.edu.boot.entity.Vo.SResumeAndNid;
import com.edu.boot.entity.Vo.SResumeAndUserVo;
import com.edu.boot.service.SResumeService;
import com.edu.boot.mapper.SResumeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author 。
* @description 针对表【s_resume】的数据库操作Service实现
* @createDate 2023-11-16 13:33:45
*/
@Service
public class SResumeServiceImpl extends ServiceImpl<SResumeMapper, SResume>
    implements SResumeService{

    @Autowired
    SResumeMapper sResumeMapper;
    @Override
    public Integer getNotesConstById(Integer uid) {
        return sResumeMapper.getNotesConstById(uid);
    }

    @Override
    public List<SResumeAndUserVo> getStuNotesAndUserInfo() {
        return sResumeMapper.getStuNotesAndUserInfo();
    }

    @Override
    public List<SResumeAndNid> getAllNotesByTid(Integer tid,Integer nid) {
        return sResumeMapper.getAllNotesByTid(tid,nid);
    }

    @Override
    public SResumeAndNid getOneTid(Integer sResumeQueryWrapper) {
        return sResumeMapper.getOneTid(sResumeQueryWrapper);
    }
    // 添加简历
    public boolean addResume(SResume resume) {
        return this.save(resume);
    }
    
    // 更新简历
    public boolean updateResume(SResume resume) {
        return this.updateById(resume);
    }
    
    // 删除简历
    public boolean deleteResume(Integer id) {
        return this.removeById(id);
    }
    
    // 查询单个简历
    public SResume getResumeById(Integer id) {
        return this.getById(id);
    }
    
    @Override
    public SResume getResumeByUId(Integer uId) {
        QueryWrapper<SResume> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("u_id",uId);
        return this.getOne(queryWrapper);
        
    }
    
    // 查询所有简历
    public List<SResume> getAllResumes() {
        return this.list();
    }
    
    @Override
    public Map<Integer, SResume> getResumeMap() {
        List<SResume> list = this.list();
        if (CollectionUtil.isNotEmpty(list)){
            Map<Integer, SResume> collect = list.stream()
                    .collect(Collectors.toMap(SResume::getTId, SResume -> SResume));
            return collect;
        }
        return null;
    }
}




